﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Assignment2
{
    class MouseHandler
    {
        private static MouseState mouseState;
        private static MouseState oldMouseState;

        private static int countMouse = 0;//count number of time user right clicks

        public static int CountMouse { get { return countMouse; } }

        //init mouse state
        public static void InitMouse()
        {
            mouseState = Mouse.GetState();
        }
        //listen to right click
        public static void RightClickListener()
        {
            if (mouseState.RightButton == ButtonState.Pressed && oldMouseState.RightButton == ButtonState.Released)
            {
                countMouse += 1;
            }
            oldMouseState = mouseState;
        }

        //listen to mouse drag
        //note:Doesn't work
        public static void MouseDragListener(ref Vector2 stringPos, ref Vector2 stringLength)
        {
            if (mouseState.LeftButton == ButtonState.Pressed)
            {
                Vector2 tmpNew= new Vector2(mouseState.X,mouseState.Y);
                if (tmpNew.X > stringPos.X && tmpNew.X < (stringPos + stringLength).X && tmpNew.Y > stringPos.Y && tmpNew.Y < (stringPos + stringLength).Y)
                {
                    Vector2 tmpOld = new Vector2(oldMouseState.X, oldMouseState.Y);
                    Vector2 dicplacement = tmpNew - tmpOld;
                    stringPos += dicplacement;
                }
            }
            oldMouseState = mouseState;
        }

    }
}
